package com.heima.common.exception;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


// 当系统抛出异常之后 都会本此异常配置类拦截
@Configuration
@RestControllerAdvice //控制层增强方法

@Slf4j
public class ExceptionCatch {

    //拦截异常后对异常的处理
    //拦截无法预知的异常
    @ExceptionHandler(Exception.class)
    public ResponseResult exceptionHand(Exception ex){
        log.error("ExceptionCatch => ex:{}",ex.getMessage());
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
    }


    @ExceptionHandler(CustomException.class)
    public ResponseResult exceptionHand2(CustomException ex){
        log.error("ExceptionCatch => ex:{}",ex.getMessage());
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
    }
}
